<template>
    <div class="container" >
      <div class="card">
        <div class="card2">
          <span class="title">Login in</span>
          <el-form
            :rules="rules"
            ref="ruleForm"
            :model="form"
            label-width="70px"
            label-position="left"
          >
            <div prop="name">
              <span>账号：</span>
                <el-input
                size="mini"
                v-model.trim="form.name"
                clearable
                prefix-icon="el-icon-user-solid"
                class="input"
                placeholder=""
              ></el-input>
            </div>
            <div prop="password">
              <span>密码：</span>
              <el-input
                size="mini"
                class="input"
                v-model.trim="form.password"
                type="password"
                show-password
                clearable
                prefix-icon="el-icon-lollipop"
              ></el-input>
            </div>
            <div>
              <el-button type="primary"  @click="register('ruleForm')"
                >注册</el-button
              >
              <el-button style="margin-left: 15px" @click="login('ruleForm')"
                >登录</el-button
              >
            </div>
          </el-form>


          <div class="square">
            <ul>
              <li></li>
              <li></li>
              <li></li>
              <li></li>
              <li></li>
            </ul>
          </div>
          <div class="circle">
            <ul>
              <li></li>
              <li></li>
              <li></li>
              <li></li>
              <li></li>
            </ul>
          </div>


        </div>
      </div>
    </div>
  </template>
  
  <script>
  import Mock from 'mockjs';
  import {setToken} from '@/utils/token';
  export default {
    name: 'Login',
  
    data() {
      return {
        form: {
          name: '',
          password: '',
        },
        rules: {
          name: [{ required: true, message: '请输入用户', trigger: 'blur' }],
          password: [
            { required: true, message: '请输入密码', trigger: 'change' },
          ],
        },
        // :style="{ backgroundImage: `url(${backgroundimg})` }"
        // backgroundimg: require("@/assets/xc4.jpg"),
      };
    },
  
    mounted() {
        console.log('hgydvcy');
    },
  
    methods: {
      register(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            const token = Mock.Random.guid();
            // this.$message.success('注册成功');
            this.$message({
                  offset:3,
                  duration:2000,
                  message: '欢迎注册 our website!'
                });
            this.$store.commit('role/SetUserInfo', this.form);
            this.$store.commit('token/setToken', token);
            setToken(token);
            this.$router.push('/home');
          }
        });
      },
      login(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.quaryData();
            const token = Mock.Random.guid();
            this.$store.commit('token/setToken', token);
            setToken(token);
          } else {
            this.$message.error('请输入用户名和密码');
          }
        });
      },
      quaryData() {
        this.$http.login().then((res) => {
            const reszult = res.data.find((i) => i.name == this.form['name']);
            if (reszult) {
              if (this.form['password'] == reszult['password']) {
                // this.$message.success('登录成功');
                this.$message({
                  offset:3,
                  duration:2000,
                  message: '欢迎登录 our website!'
                });
                this.$store.commit('role/SetUserInfo', this.form);
                this.$router.push('/home');
              } else {
                this.$message.error('密码错误');
              }
            } else {
              this.$message.error('该用户未注册！请注册');
            }
          })
          .catch(() => {});
      },
    },
  };
  </script>
  
  <style scoped>
   .title{
    font-size: 10px;
    margin-top: 5px;
   }
    .container {
      width: 100vw;
      position: relative;
      height: 100vh;
  /* background-size: 100% 100%; */
      background: linear-gradient(200deg, #f2c69b, #c4c2ec);
      overflow: hidden;
    }
    .card {
        z-index: 10;
        width: 160px;
        height: 150px;
        margin: 15px auto;
        background-image: linear-gradient(163deg, #f1a036 0%, #9a83ee 100%);
        border-radius: 20px;
        transition: all 0.3s;
      }
    
      .card2 {
        z-index: 10;
        width: 100%;
        height: 100%;
        border-radius: 20px;
        background: linear-gradient(357deg, #cfcdcc 25%, #62b7ef 75%);
        transition: all 0.2s;
        display: flex;
        text-align: center;
        flex-direction: column;
        /* justify-content: space-evenly; */
        align-items: center;
        color: white;
      }
      .el-form-item {
        display: flex;
        flex-direction: row;
        width: 100px;
        }

        .input{
          margin-top: 10px;
          margin-bottom: 10px;
          width: 110px;
          height: 30px;
        }
        /deep/.el-input__inner{
          height: 23px !important;
        }

        .el-button {
          background:transparent;
          color: rgb(253, 253, 253);
          width: 40px;
          height: 5px;
          text-align: center;
          font-size: 5px;
          padding: 5px 9px 7px 9px;
        }

        span{
          font-size: 6px;
          color: #5c5c5c;
        }
    
      .card2:hover {
        transform: scale(0.98);
        border-radius: 20px;
      }
    
      .card:hover {
        box-shadow: 0px 0px 30px 1px rgba(247, 185, 97, 0.3);
      }

ul li {
  position: absolute;
  border: 1px solid #fff;
  background-color: #fff;
  width: 5px;
  height: 5px;
  border-radius: 3px;
  list-style: none;
  opacity: 0;
}
.square li {
  top: 40vh;
  left: 60vw;
  /* 执行动画：动画名 时长 线性的 无限次播放 */
  animation: square 10s linear infinite;
}
.square li:nth-child(2) {
  top: 80vh;
  left: 10vw;
  /* 设置动画延迟时间 */
  animation-delay: 2s;
}
.square li:nth-child(3) {
  top: 80vh;
  left: 85vw;
  /* 设置动画延迟时间 */
  animation-delay: 4s;
}
.square li:nth-child(4) {
  top: 10vh;
  left: 70vw;
  /* 设置动画延迟时间 */
  animation-delay: 6s;
}
.square li:nth-child(5) {
  top: 10vh;
  left: 10vw;
  /* 设置动画延迟时间 */
  animation-delay: 8s;
}
.circle li {
  bottom: 0;
  left: 15vw;
  /* 执行动画 */
  animation: circle 10s linear infinite;
}
.circle li:nth-child(2) {
  left: 35vw;
  /* 设置动画延迟时间 */
  animation-delay: 2s;
}
.circle li:nth-child(3) {
  left: 55vw;
  /* 设置动画延迟时间 */
  animation-delay: 6s;
}
.circle li:nth-child(4) {
  left: 75vw;
  /* 设置动画延迟时间 */
  animation-delay: 4s;
}
.circle li:nth-child(5) {
  left: 90vw;
  /* 设置动画延迟时间 */
  animation-delay: 8s;
}

/* 定义动画 */
@keyframes square {
  0% {
    transform: scale(0) rotateY(0deg);
    opacity: 1;
  }
  100% {
    transform: scale(5) rotateY(1000deg);
    opacity: 0;
  }
}
@keyframes circle {
  0% {
    transform: scale(0) rotateY(0deg);
    opacity: 1;
    bottom: 0;
    border-radius: 0;
  }
  100% {
    transform: scale(5) rotateY(1000deg);
    opacity: 0;
    bottom: 90vh;
    border-radius: 50%;
  }
}
    </style>